package com.kaiji.service.impl;

import com.kaiji.exhandler.BaseDao;
import com.kaiji.model.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userDetailService")
public class UserDetailServiceImpl implements UserDetailsService {

    @Resource
    private BaseDao<User> baseDao;

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User userModel = new User();
        userModel.setPhone(username);
        List<User> users = baseDao.select(userModel);
        return (UserDetails) users.get(0);
    }
}
